package PersistanceLayer;

import BusinessLayer.Enseignant;

import PersistanceLayer.DAO;

import BusinessLayer.Etudiant;
import PersistanceLayer.DAO;


import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;

import jdbc.ConnectionToOracle;

public class EnseignantDAO extends DAO<Enseignant> {

    private static final EnseignantDAO instance = new EnseignantDAO();

     /* Methode permettant de recuperer l'objet unique de type AnneeDAO
     */
    public final static EnseignantDAO getInstance() {
        return instance;
    }

    @Override
    public boolean create(Enseignant obj) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean update(Enseignant obj) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean update(Enseignant ancien, Enseignant nouveau) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Enseignant find(Enseignant obj) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean delete(Enseignant obj) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public ArrayList<Enseignant> getListe() {
        String id;
    	String numEns;
    	String mdp;
    	String login;
    	String nom = null;
    	String prenom = null;
    	String mail = null;
    	String sexe = null;
    	ArrayList<Enseignant> ensEns= new ArrayList<Enseignant>();
    	
    	try {
    		
    		java.sql.Statement state =this.connect.createStatement();
    		
			ResultSet res = this.connect.createStatement()
			.executeQuery("SELECT * FROM ENSEIGNANT");
		
			ResultSet res2 = null;
			
			while(res.next()){	
				
				res2 = this.connect.createStatement().executeQuery
				("SELECT * FROM  PERSONNE WHERE ID = '" + res.getObject(1)+"'");
				
				
				if(res.getObject(1) != null)
					id = res.getObject(1).toString();
				else
					id = "";
				
				if(res.getObject(2) != null)
					numEns = res.getObject(2).toString();
				else
					numEns = "";
				
				if(res.getObject(4) != null)
					mdp = res.getObject(4).toString();
				else
					mdp = "";
				
				if (res.getObject(3) != null)
					login = res.getObject(3).toString();
				else
					login = "";
				
				/* informations de personne
				 * 
				 */
				while(res2.next()){
				if (res2.getObject(2) != null)
					nom = res2.getObject(2).toString();
				else
					nom = "";
				
				if (res2.getObject(3) != null)
					prenom = res2.getObject(3).toString();
				else
					prenom = "";
				if (res2.getObject(3) != null)
					sexe = res2.getObject(3).toString();
				else
					sexe = "";
				
				if (res2.getObject(4) != null)
					mail = res2.getObject(4).toString();
				else
					mail = "";
				}
				
				
				ensEns.add(new Enseignant(nom,prenom,sexe,mail,numEns,mdp,login));
				
			
			}
			
			state.close();
			res.close();
			res2.close();
			
			return ensEns;
    	} catch (SQLException e) {
			// 
    		
			e.printStackTrace();
			return null;
		}
    	
    	
    }


	@Override
	public ArrayList<Enseignant> getListe(String nomAnnee) {
		// TODO Auto-generated method stub
		return null;
	}



	@Override
	public String getNom(String name) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean update(String a, String b, String c, String d) {
		// TODO Auto-generated method stub
		return false;
	}
	
	

}